{% extends "catalog/base_generic.html" %}

{% block title %}欢迎访问图书馆{% endblock %}

{% block content %}
<h1 class="page-header">
    <i class="fas fa-home me-2"></i>欢迎访问图书馆
</h1>

<div class="row g-4">
    <!-- 最新图书 -->
    <div class="col-md-6">
        <div class="card h-100">
            <div class="card-body">
                <h5 class="card-title">
                    <i class="fas fa-book-open me-2"></i>最新图书
                </h5>
                <div class="list-group list-group-flush">
                    {% for book in latest_books %}
                    <a href="{{ book.get_absolute_url }}" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h6 class="mb-1">{{ book.title }}</h6>
                            <small class="text-muted">{{ book.author }}</small>
                        </div>
                        <p class="mb-1 text-truncate">{{ book.summary }}</p>
                    </a>
                    {% empty %}
                    <p class="text-muted">暂无图书</p>
                    {% endfor %}
                </div>
            </div>
        </div>
    </div>

    <!-- 借阅统计 -->
    <div class="col-md-6">
        <div class="card h-100">
            <div class="card-body">
                <h5 class="card-title">
                    <i class="fas fa-chart-pie me-2"></i>借阅统计
                </h5>
                <div class="row text-center g-3">
                    <div class="col-6">
                        <div class="p-3 border rounded bg-light">
                            <h3 class="text-primary">{{ num_books }}</h3>
                            <p class="mb-0">馆藏图书</p>
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="p-3 border rounded bg-light">
                            <h3 class="text-success">{{ num_instances_available }}</h3>
                            <p class="mb-0">可借图书</p>
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="p-3 border rounded bg-light">
                            <h3 class="text-info">{{ num_authors }}</h3>
                            <p class="mb-0">入驻作者</p>
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="p-3 border rounded bg-light">
                            <h3 class="text-warning">{{ num_visits }}</h3>
                            <p class="mb-0">访问次数</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {% if user.is_authenticated %}
    <!-- 我的借阅 -->
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                <h5 class="card-title">
                    <i class="fas fa-bookmark me-2"></i>我的借阅
                </h5>
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>图书</th>
                                <th>借阅日期</th>
                                <th>应还日期</th>
                                <th>状态</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for instance in user_borrowed %}
                            <tr>
                                <td>
                                    <a href="{{ instance.book.get_absolute_url }}">{{ instance.book.title }}</a>
                                </td>
                                <td>{{ instance.borrower_date|date:"Y-m-d" }}</td>
                                <td>{{ instance.due_back|date:"Y-m-d" }}</td>
                                <td>
                                    {% if instance.is_overdue %}
                                    <span class="badge bg-danger">已逾期</span>
                                    {% else %}
                                    <span class="badge bg-success">借阅中</span>
                                    {% endif %}
                                </td>
                            </tr>
                            {% empty %}
                            <tr>
                                <td colspan="4" class="text-center">暂无借阅记录</td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    {% endif %}
</div>
{% endblock %} 